package com.ruoyi.web.controller.news.api;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.news.NewsImportantDynamic;
import com.ruoyi.system.domain.news.query.NewsImportantDynamicQuery;
import com.ruoyi.system.domain.news.vo.NewsImportantDynamicVo;
import com.ruoyi.system.service.news.NewsImportantDynamicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/news/newsImportantDynamic")
@Api(value = "newsImportantDynamicApiController", tags  = "要闻动态Api")
public class NewsImportantDynamicApiController extends BaseController {

	@Resource
	private NewsImportantDynamicService newsImportantDynamicService;

	@ApiOperation(value = "获取单个要闻动态信息", notes = "获取单个要闻动态信息")
	@GetMapping("/getById")
	public R<NewsImportantDynamic> getById(@RequestParam(value = "id") Long id) {
		NewsImportantDynamicQuery newsImportantDynamicQuery = new NewsImportantDynamicQuery();
		newsImportantDynamicQuery.setId(id);
		List<NewsImportantDynamicVo> newsImportantDynamicList = newsImportantDynamicService.getNewsImportantDynamicList(newsImportantDynamicQuery);
		if (newsImportantDynamicList!=null&&newsImportantDynamicList.size()>0) {
			return R.ok(newsImportantDynamicList.get(0));
		} else {
			return R.fail("数据不存在");
		}
	}

	@ApiOperation(value = "获取要闻动态信息列表")
	@PostMapping(value = "/list")
	public R<PageInfo<NewsImportantDynamicVo>> list(@RequestBody NewsImportantDynamicQuery newsImportantDynamicQuery) {
        newsImportantDynamicQuery.setIsEnable("1");
		List<NewsImportantDynamicVo> newsImportantDynamicList = newsImportantDynamicService.getNewsImportantDynamicList(newsImportantDynamicQuery);
		return R.ok(new PageInfo<>(newsImportantDynamicList));
	}
}
